package org.aplombh.java.leetcode.dailyTopic;

import java.util.ArrayList;
import java.util.List;

public class _816模糊坐标 {
    public static void main(String[] args) {
        System.out.println(new Solution816_1().ambiguousCoordinates("(01)"));
    }
}

class Solution816_1 {
    public List<String> ambiguousCoordinates(String s) {

        if (s.length() <= 3)
            return null;

        List<String> ans = new ArrayList<>();

        if (s.length() == 4 && (s.charAt(1) != '0' || s.charAt(2) != '0')) {
            ans.add("(" + s.charAt(1) + ", " + s.charAt(2) + ")");
        } else {

            // 先分离
            for (int i = 2; i < s.length() - 1; i++) {

                String left = s.substring(1, i);
                String right = s.substring(i, s.length() - 1);

                List<String> leftList = getNumber(left);
                List<String> rightList = getNumber(right);

                // 后加点

                if (leftList == null || rightList == null)
                    continue;

                for (String l : leftList) {
                    for (String r : rightList) {
                        ans.add("(" + l + ", " + r + ")");
                    }
                }

            }
        }

        return ans;
    }

    private List<String> getNumber(String s) {

        List<String> ans = new ArrayList<>();

        // s为空
        if (s == null || s.equals("")) {
            return null;
        }
        // 长度为0直接加入
        else if (s.length() == 1) {
            ans.add(s);

            // 首字母为0 只能是小数
        } else if (s.charAt(0) == '0') {
            if (s.charAt(s.length() - 1) != '0') {
                ans.add("0." + s.substring(1));
            } else {
                return null;
            }

            // 尾字母尾0 只能是整数
        } else if (s.charAt(s.length() - 1) == '0') {
            ans.add(s);

            // 其他情况
        } else {
            for (int i = 1; i < s.length(); i++) {
                ans.add(s.substring(0, i) + "." + s.substring(i));
            }
            ans.add(s);
        }

        return ans;

    }
}